package com.paic.mhis.hcpms.agreement.protocol.biz.validator;

import java.util.Map;

import org.springframework.stereotype.Component;

import com.paic.mhis.common.validator.HcpmsBaseValidator;
import com.paic.mhis.common.validator.MapValidator;
import com.paic.mhis.common.validator.ValidatorList;
import com.paic.mhis.hcpms.agreement.protocol.util.GlogalBudgetValidatorConstants;
import com.paic.pafa.app.biz.bo.validation.ValidStatus;

@Component("glogalBudgetValidator")
public class GlogalBudgetValidator extends HcpmsBaseValidator {

	@Override
	public Map<Object, Object> validate(Map<Object, Object> fieldMap) {
		validatorList = new ValidatorList();
		validatorList.setValidateAll(true);

		// 常规验证
		validateFieldNotNull();
		validateNumber();

		ValidStatus validStatus = validatorList.validate(fieldMap);

		return throwErrorMassage(validStatus);
	}

	/* 验证非空字段 */
	private void validateFieldNotNull() {
		validatorList
				.add(MapValidator
						.require(
								GlogalBudgetValidatorConstants.ANNUAL_AMOUNT_REQUIRE_VALIDATE,
								GlogalBudgetValidatorConstants.ANNUAL_AMOUNT_REQUIRE_VALIDATE_MSG));
		validatorList.add(MapValidator.require(
				GlogalBudgetValidatorConstants.ANNUAL_AMOUNT_RATIO_TYPE,
				GlogalBudgetValidatorConstants.ANNUAL_AMOUNT_RATIO_TYPE_MSG));
	}

	/* 验证数字长度 */
	private void validateNumber() {
		validatorList
				.add(MapValidator
						.number(GlogalBudgetValidatorConstants.ANNUAL_AMOUNT_NUMBER_REQUIRE,
								14,
								2,
								GlogalBudgetValidatorConstants.ANNUAL_AMOUNT_NUMBER_REQUIRE_MSG));
		validatorList
				.add(MapValidator
						.number(GlogalBudgetValidatorConstants.RATIOSTDVALUE_NUMBER_REQUIRE,
								5,
								4,
								GlogalBudgetValidatorConstants.RATIOSTDVALUE_NUMBER_REQUIRE_MSG));
		validatorList
				.add(MapValidator
						.number(GlogalBudgetValidatorConstants.RATIOUSINGVALUE_NUMBER_REQUIRE,
								5,
								4,
								GlogalBudgetValidatorConstants.RATIOUSINGVALUE_NUMBER_REQUIRE_MSG));
	}
}
